#pragma once

#include <memory>
#include <thread>
#include <cmath>
#include <chrono>
#include <cassert>
#include "utils/utils.h"
#include "model/SubscriberNode.h"
#include "model/ClientNode.h"
#include "protocol/routeinfo.pb.h"
#include "protocol/transport.pb.h"

#include "base/Uri.h"
#include "base/Traits.h"
#include "base/Serializer.h"
#include "base/Message.h"
#include "base/Define.h"
#include "consumer/client/RouteInfoSelector.h"
#include "base/MessageLoop.h"

namespace zeroplus::mq::consumer
{
    class ConsumerMediator;
    class RouteInfoDownloader
    {
    private:
        std::shared_ptr<ClientNode> client_;
        MessageLoop loop_;
        std::shared_ptr<ConsumerMediator> mediator_;
        RouteInfoSelector selector_;

    public:
        RouteInfoDownloader(std::shared_ptr<ConsumerMediator> mediator, std::string uri);

        ~RouteInfoDownloader();

        void Start();

        void SetTopicName(const std::string &topic);

        transport::QueryRouteInfoResponse SendQueryRouteInfoRequest(const std::string &topic);
    };
}
